package com.jingjiu.homeservicesbiz.controller;

import java.util.List;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jingjiu.homeservicesapi.domain.DiseaseInfo;
import com.jingjiu.homeservicesapi.util.R;

import com.jingjiu.homeservicesbiz.service.DiseaseInfoServiceImpl;


import org.springdoc.core.annotations.ParameterObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * 疾病信息：用于存储具体疾病的介绍与科普内容Controller
 * 
 * @author ruoyi
 * @date 2025-04-16
 */
@RestController
@RequestMapping("/system/disease/info")
public class DiseaseInfoController
{

    @Autowired
    private DiseaseInfoServiceImpl diseaseInfoService;




    @GetMapping("/page")
    public R<Page<DiseaseInfo>> getPage(@ParameterObject Page<DiseaseInfo> page,
                                        @ParameterObject DiseaseInfo diseaseInfo) {

        Page<DiseaseInfo> diseaseInfoPage = diseaseInfoService.selectPage(page, diseaseInfo);
        if(diseaseInfoPage==null)
            return R.failed();
        // 调用 Service 层进行分页查询
        return R.ok(diseaseInfoPage);
    }



    /**
     * 新增保存疾病信息：用于存储具体疾病的介绍与科普内容
     */


    @PostMapping("/add")
    @ResponseBody
    public R addSave(@RequestBody DiseaseInfo diseaseInfo)
    {
        int row = diseaseInfoService.insertDiseaseInfo(diseaseInfo);
        if(row!=1)
            return R.failed();
        return R.ok(row);
    }

    /**
     * 修改疾病信息：用于存储具体疾病的介绍与科普内容
     */

    @GetMapping("/get/{id}")
    public R<DiseaseInfo> getById(@PathVariable("id") Long id)
    {
        DiseaseInfo diseaseInfo = diseaseInfoService.selectDiseaseInfoById(id);
        if(diseaseInfo==null)
            return R.failed();
        return   R.ok(diseaseInfo);

    }

    /**
     * 修改保存疾病信息：用于存储具体疾病的介绍与科普内容
     */

    @PostMapping("/edit")
    public R  editSave(@RequestBody DiseaseInfo diseaseInfo)
    {
        int row = diseaseInfoService.updateDiseaseInfo(diseaseInfo);
        if(row!=1)
            return R.failed();
        return R.ok(row);
    }

    /**
     * 删除疾病信息：用于存储具体疾病的介绍与科普内容
     */

    @PostMapping( "/remove")
    @ResponseBody
    public R remove(long id)
    {
        int row = diseaseInfoService.deleteDiseaseInfoById(id);
        if(row!=1)
            return R.failed();
        return R.ok(row);
    }
}
